/*
 * NaryRule.java
 *
 * Created on July 13, 2006, 4:52 PM
 *
 */

package galronnlp.cfg.grammar;

import galronnlp.util.Symbol;
import java.util.LinkedList;
import java.util.List;

/**
 *
 * @author Daniel A. Galron
 */
public class NaryRule implements Rule {
    
    private final int arity;
    private LinkedList<Symbol> RHS;
    private Symbol LHS;
    
    
    /** 
     * Creates a new instance of NaryRule 
     * @param LHS the left hand side of the rule
     * @param RHS a <code>LinkedList</code> of <code>Symbol</code>s representing the right hand side of the rule
     */
    public NaryRule(Symbol LHS, LinkedList<Symbol> RHS) {
        this.LHS = LHS;
        this.RHS = RHS;
        this.arity = RHS.size();
    }    

    /**
     * @return the number of RHS Symbols of the rule
     */
    public int arity() {
        return this.RHS.size();
    }

    /**
     * @return the LHS of the rule as a <code>Symbol</code>
     */
    public Symbol LHS() {
        return this.LHS;
    }

    /**
     * @return the RHS of the rule as a <code>List</code>
     */
    public List<Symbol> RHS() {
        return this.RHS;
    }

    public boolean hasTerminalRHS() {
        return false;
    }
    
    public String toString() {
        String ret = this.LHS + " --> " + this.RHS.get(0);
        for(int i = 1; i < this.RHS.size(); i++) {
            ret += ", " + this.RHS.get(i);
        }
        return ret + "\n";
    }
}
